import os
import logging
from XTestRunner import HTMLTestRunner
from integration.testcases.test_case import TestCase
import unittest


def get_project_path():
    current_file_path = os.path.abspath(__file__)
    project_path = os.path.dirname(os.path.dirname(current_file_path))
    return project_path


def sep(path, add_before=False, add_after=False):
    # 拼接传入的数组
    all_path = os.sep.join(path)
    # 如果before为TRUE，那就在路径前面加“/”
    if add_before:
        all_path = os.sep + all_path
    # 如果after为TRUE，那就在路径后面加“/”
    if add_after:
        all_path = all_path + os.sep
    return all_path


def is_blank(name):
    if name is None or name.strip() == '':
        return True
    return False


def XTRunner(report_name, title):
    suite = unittest.defaultTestLoader.discover("./integration/testcases", "test_case.py")
    with open(r"./static/reports/" + report_name, 'wb') as f:
        HTMLTestRunner(stream=f, title=title, rerun=0).run(suite)


if __name__ == '__main__':
    print(get_project_path())
    print(get_project_path() + sep([r"static\soar", "a.json"], add_before=True))
    print(sep([r"integration\testdata", 'zheng_longguo.xlsx'], add_before=True))
